package com.edu.exam.enums;

/**
 * 基础评分体系枚举
 *
 * @author System
 * @version 1.0.0
 */
public enum FoundationGradingSystem {
    PERCENTAGE("PERCENTAGE", "百分制"),
    GPA_4_0("GPA_4_0", "4.0绩点制"),
    GPA_5_0("GPA_5_0", "5.0绩点制"),
    LEVEL_4("LEVEL_4", "四级制"),
    LEVEL_5("LEVEL_5", "五级制"),
    PASS_FAIL("PASS_FAIL", "通过/不通过制"),
    POINT_100("POINT_100", "百分制"),
    POINT_10("POINT_10", "十分制");

    private final String code;
    private final String description;

    FoundationGradingSystem(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 从代码创建枚举实例
     *
     * @param code 枚举代码
     * @return 对应的枚举实例
     * @throws IllegalArgumentException 如果代码无效
     */
    public static FoundationGradingSystem fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Code cannot be null or empty");
        }
        for (FoundationGradingSystem system : values()) {
            if (system.getCode().equals(code)) {
                return system;
            }
        }
        throw new IllegalArgumentException("Unknown code: " + code);
    }

    /**
     * 从描述创建枚举实例
     *
     * @param description 枚举描述
     * @return 对应的枚举实例
     * @throws IllegalArgumentException 如果描述无效
     */
    public static FoundationGradingSystem fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("Description cannot be null or empty");
        }
        for (FoundationGradingSystem system : values()) {
            if (system.getDescription().equals(description)) {
                return system;
            }
        }
        throw new IllegalArgumentException("Unknown description: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}